package com.tony.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author tony
 * @Date 2018/12/6
 */
public class ThreadExecutors {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        int nodeCnt = 48;
        ExecutorService executor = Executors.newFixedThreadPool(16);
        List<FutureTask<Integer>> futuerList = new ArrayList<>(nodeCnt);
        for (int i = 0; i < nodeCnt; i++) {
            final int node = i;
            FutureTask<Integer> futureTask = new FutureTask<>(new Callable<Integer>() {
                @Override
                public Integer call() {
                    int rtn = 0;
                    try {
                        System.out.println("this is node:"+node);
                        rtn = 1;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return rtn;
                }

            });
            futuerList.add(futureTask);
            executor.execute(futureTask);
        }
        int cnt = 0;
        for (FutureTask<Integer> futureTask : futuerList) {
            cnt = cnt + futureTask.get();
        }
        if(cnt ==48){
            System.out.println("END");
        }else{
            System.out.println("ERROR");
        }
    }
}
